---
slug: /api/cache-volumes
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Cache Volumes

Volume caching involves caching specific parts of the filesystem and reusing them on subsequent function calls if they are unchanged. This is especially useful when dealing with package managers such as `npm`, `maven`, `pip` and similar. Since these dependencies are usually locked to specific versions in the application's manifest, re-downloading them on every session is inefficient and time-consuming. By using a cache volume for these dependencies, Dagger can reuse the cached contents across Dagger Function runs and reduce execution time.

Here's an example:

<Tabs groupId="language">
<TabItem value="Dagger CLI">

```shell
dagger core container \
  from --address=node:21 \
  with-directory --path=/src --directory=https://github.com/dagger/hello-dagger \
  with-workdir --path=/src \
  with-mounted-cache --path=/root/.npm --cache=node-21 \
  with-exec --args="npm","install"
```

</TabItem>
<TabItem value="Go">

```go file=../cookbook/snippets/cache-dependencies/go/main.go
```

</TabItem>
<TabItem value="Python">

```python file=../cookbook/snippets/cache-dependencies/python/main.py
```

</TabItem>
<TabItem value="TypeScript">

```typescript file=../cookbook/snippets/cache-dependencies/typescript/index.ts
```

</TabItem>
</Tabs>

This example will take some time to complete on the first run, as the cache volumes will not exist at that point. Subsequent runs will be significantly faster (assuming there is no other change), since Dagger will simply use the dependencies from the cache volumes instead of downloading them again.
